package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.GlueBaseMaterial;
import com.ruoyi.system.mapper.GlueBaseMaterialMapper;
import com.ruoyi.system.service.IGlueBaseMaterialService;
import com.ruoyi.system.service.IGlueCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 基材信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class GlueBaseMaterialServiceImpl extends ServiceImpl<GlueBaseMaterialMapper,GlueBaseMaterial> implements IGlueBaseMaterialService
{
    @Autowired
    private GlueBaseMaterialMapper glueBaseMaterialMapper;

    @Autowired
    private IGlueCategoryService glueCategoryService;
    /**
     * 查询基材信息
     *
     * @param id 基材信息主键
     * @return 基材信息
     */
    @Override
    public GlueBaseMaterial selectGlueBaseMaterialById(Long id)
    {
        return glueBaseMaterialMapper.selectGlueBaseMaterialById(id);
    }

    /**
     * 查询基材信息列表
     *
     * @param glueBaseMaterial 基材信息
     * @return 基材信息
     */
    @Override
    public List<GlueBaseMaterial> selectGlueBaseMaterialList(GlueBaseMaterial glueBaseMaterial)
    {
        //有值就递归查出所有子集
        if (!ObjectUtils.isEmpty(glueBaseMaterial.getClassifyId())){
            List<Long> ids = glueCategoryService.getIds(glueBaseMaterial.getClassifyId());
            glueBaseMaterial.setClassifyIds(ids);
        }

        return glueBaseMaterialMapper.selectGlueBaseMaterialList(glueBaseMaterial);
    }

    /**
     * 新增基材信息
     *
     * @param glueBaseMaterial 基材信息
     * @return 结果
     */
    @Override
    public int insertGlueBaseMaterial(GlueBaseMaterial glueBaseMaterial)
    {
        glueBaseMaterial.setCreateTime(DateUtils.getNowDate());
        glueBaseMaterial.setCreateBy(SecurityUtils.getUserId().toString());
        return glueBaseMaterialMapper.insertGlueBaseMaterial(glueBaseMaterial);
    }

    /**
     * 修改基材信息
     *
     * @param glueBaseMaterial 基材信息
     * @return 结果
     */
    @Override
    public int updateGlueBaseMaterial(GlueBaseMaterial glueBaseMaterial)
    {
        glueBaseMaterial.setUpdateTime(DateUtils.getNowDate());
        return glueBaseMaterialMapper.updateGlueBaseMaterial(glueBaseMaterial);
    }

    /**
     * 批量删除基材信息
     *
     * @param ids 需要删除的基材信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueBaseMaterialByIds(Long[] ids)
    {
        return glueBaseMaterialMapper.deleteGlueBaseMaterialByIds(ids);
    }

    /**
     * 删除基材信息信息
     *
     * @param id 基材信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueBaseMaterialById(Long id)
    {
        return glueBaseMaterialMapper.deleteGlueBaseMaterialById(id);
    }


    /**
     * 基材材质三级目录
     * @param dto
     * @return
     */
    @Override
    public List<String> getModel(String dto) {
     return    glueBaseMaterialMapper.getModel(dto);

    }


}
